/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.basics.bean;

import java.util.Enumeration;
import java.util.Iterator;

/**
 * This class allow to transform an <code>Enumeration</code> to an
 * <code>Iterator</code>.
 * 
 * @param <TYPE>
 *          the type of the elements of the <code>Iterator</code>.
 */
public class IteratorEnumeration<TYPE>
    implements Iterator<TYPE>
{

  /**
   * the wrapped <code>Enumeration</code>.
   */
  private transient final Enumeration<TYPE> enumeration;



  /**
   * Constructor.
   * 
   * @param enumeration
   *          the wrapped <code>Enumeration</code>
   */
  public IteratorEnumeration(final Enumeration<TYPE> enumeration)
  {
    this.enumeration = enumeration;
  }



  /**
   * Returns <code>true</code> if the iteration has more elements. (In other
   * words, returns <code>true</code> if <code>next</code> would return an
   * element rather than throwing an exception.)
   * 
   * @return <code>true</code> if the iterator has more elements
   * @see java.util.Iterator#hasNext()
   */
  public boolean hasNext()
  {
    return enumeration.hasMoreElements();
  }



  /**
   * Returns the next element in the iteration. Calling this method repeatedly
   * until the <code>hasNext()</code> method returns false will return each
   * element in the underlying collection exactly once.
   * 
   * @return the next element in the iteration
   * @see java.util.Iterator#next()
   */
  public TYPE next()
  {
    return enumeration.nextElement();
  }



  /**
   * Removes from the underlying collection the last element returned by the
   * iterator (optional operation). This method can be called only once per call
   * to <code>next</code>. The behavior of an iterator is unspecified if the
   * underlying collection is modified while the iteration is in progress in any
   * way other than by calling this method.
   * 
   * @see java.util.Iterator#remove()
   */
  public void remove()
  {
    throw new UnsupportedOperationException();
  }

}
